﻿var controller = this.lookupController();
var status = controller.analysis().status;
var vm = this.lookupViewModel();
var isInquiryCall = vm.get('NebulogyForm.isInquiryCall');
var ukCrossCharge = ref.UKCrossCharge.getValue();

if (isInquiryCall == 1 && record.previousValues) {
    if (context.field == 'TotalPrice') {
        var newValue = record.get('TotalPrice');
        var oldValue = record.get('originalTotalPrice');
        if (newValue > oldValue) {
            Ext.Msg.alert('System Tips', 'Total Price CANNOT be higher than the previous value.');
            record.set(context.field, record.previousValues[context.field]);
        } else {
            record.set('PriceDiffer', oldValue - newValue);
        }
    }
}
if (context.field == 'TotalPrice' || context.field == 'TaxRate') {
    if (record.get('TaxRate')) {
        var totalPrice = record.get('TotalPrice') || 0;
        record.set('GrossAmount', (totalPrice * (1 + parseFloat(record.get('TaxRate')))).toFixed(2));
    }
} else if (context.field == 'VendorCode') {
    var _editor = grid.getColumns()[context.colIdx].getEditor();

    Ext.each(_editor.store.data.items, function (r) {
        if (r.get('code') == record.get('VendorCode')) {
            record.set('VendorName', r.get('_name'));
        }
    });
}